//
//  ContactPhone.swift
//  PeoplePickerNavigationController
//
//  Created by tkgz on 16/5/26.
//  Copyright © 2016年 tao.520it. All rights reserved.
//

import UIKit
import AddressBookUI

class ContactPhone: NSObject {
    // 目前获取不到
    var localizedPhoneLabel = ""
    var phone = ""
    
    init(phoneValues: ABMutableMultiValue, index: Int) {
        // 获得标签名
        let phoneLabel = ABMultiValueCopyLabelAtIndex(phoneValues, index)?.takeRetainedValue() as? String ?? ""
        // 转为本地标签名（能看得懂的标签名，比如work、home）
        localizedPhoneLabel = ABAddressBookCopyLocalizedLabel(phoneLabel).takeRetainedValue() as String
        phone = ABMultiValueCopyValueAtIndex(phoneValues, index).takeRetainedValue() as? String ?? ""
    }
    
    class func contactPhones(phoneValues: ABMutableMultiValue) -> [ContactPhone] {
        var contactPhones: [ContactPhone] = []
        for i in 0 ..< ABMultiValueGetCount(phoneValues){
            let contactPhone = ContactPhone(phoneValues: phoneValues, index: i)
            contactPhones.append(contactPhone)
        }
        
        return contactPhones
    }
    
    deinit {
        print("ContactPhone: deinit")
    }
}
